/*
 * Created on Aug 31, 2005 
 */
package net.sf.google.talk.eclipse.views;

import net.sf.google.talk.eclipse.EclipsePlugin;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class GroupFilterDialog extends Dialog {
	public static final String LAST_REGEX = GroupFilterDialog.class.getName()+".last_regex";
    private String regex;
    private Text regexText;

    public String getRegex() {
		return regex;
	}

	public void setRegex(String regex) {
		this.regex = regex;
	}

	protected GroupFilterDialog(Shell parentShell) {
        super(parentShell);
        // TODO Auto-generated constructor stub
    }

    protected Control createContents(Composite parent) {
        parent.setLayout(new GridLayout(2, true));
        Label l = new Label(parent, SWT.NONE);
        l.setText("Group regula expression:");
        regexText = new Text(parent, SWT.NONE);
        regexText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        regexText.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                regex = regexText.getText();
            }});
        
        // Fill defaults with stored preferences
        IPreferenceStore store = EclipsePlugin.getDefault().getPreferenceStore();
        String un = store.getString(LAST_REGEX);
        regexText.setText(un);
        
        regexText.setText(store.getString(LAST_REGEX));
        
        return super.createContents(parent);
    }

	@Override
	protected void okPressed() {
        IPreferenceStore store = EclipsePlugin.getDefault().getPreferenceStore();
        store.setValue(LAST_REGEX, regex);
		super.okPressed();
	}

}
